//
//  mimaViewController.m
//  shuilijuOASystem
//
//  Created by michael on 17/1/5.
//  Copyright © 2017年 czd. All rights reserved.
//
#import "Toast+UIView.h"
#import "UIViewExt.h"
#import "mimaViewController.h"

@interface mimaViewController ()

@end

@implementation mimaViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self initview];
       //点击手势
 UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(keybordDown)];
    [self.view addGestureRecognizer:tap];
  UIBarButtonItem * rightIem = [[UIBarButtonItem alloc] initWithTitle:@"更改" style:UIBarButtonItemStylePlain target:self action:@selector(searchAction)];
        self.navigationItem.rightBarButtonItem = rightIem;

    // Do any additional setup after loading the view.
}
- (void)keybordDown {
      [self.view endEditing:YES];
}
-(void)searchAction{

if ([_oldField.text length ]==0) {
        [self.view makeToast:@"请输入旧密码"];
}else if ([_nowField.text length ]==0) {
        [self.view makeToast:@"请输入新密码"];
}else if ([_nowField2.text length ]==0) {
        [self.view makeToast:@"请重新输入密码"];
}else{

 if ([_oldField.text isEqualToString:[[NSUserDefaults standardUserDefaults] objectForKey:@"pwdId"]]) {
 
  if ([_nowField.text isEqualToString:_nowField2.text]) {
  [self loaddata];
  }else{
          [self.view makeToast:@"密码输入错误"];
  }
}else{
        [self.view makeToast:@"旧密码输入错误!"];
}



}
  
}
- (void)initview{
  UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 74, 120, 40)];
  label.text = @"旧密码 :";
  label.font = [UIFont systemFontOfSize:14];
  [self.view addSubview:label];
  
  UILabel *label2 = [[UILabel alloc]initWithFrame:CGRectMake(10, label.bottom +10, 120, 40)];
  label2.text = @"请输入新密码 :";
  label2.font = [UIFont systemFontOfSize:14];
  [self.view addSubview:label2];
  
   UILabel *label3 = [[UILabel alloc]initWithFrame:CGRectMake(10, label2.bottom +10, 120, 40)];
  label3.text = @"请重新输入密码 :";
  label3.font = [UIFont systemFontOfSize:14];
  [self.view addSubview:label3];

  
   _oldField = [[UITextField alloc]init];
  _oldField.frame = CGRectMake(label.right, label.top+10, KScreenWidth-150, 30);
   UIColor *myColor = [UIColor colorWithWhite:0.5 alpha:0.2];
  _oldField.backgroundColor = myColor;
_oldField.secureTextEntry = YES;
  [_oldField setFont:[UIFont systemFontOfSize:13]];
  _oldField.textAlignment = NSTextAlignmentLeft;
  _oldField.delegate = self;
   [self.view addSubview:_oldField];

_nowField = [[UITextField alloc]init];
  _nowField.frame = CGRectMake(label.right, label2.top+10, KScreenWidth-150, 30);
  _nowField.backgroundColor = myColor;
_nowField.secureTextEntry = YES;
  [_nowField setFont:[UIFont systemFontOfSize:13]];
  _nowField.textAlignment = NSTextAlignmentLeft;
  _nowField.delegate = self;
   [self.view addSubview:_nowField];

_nowField2 = [[UITextField alloc]init];
  _nowField2.frame = CGRectMake(label.right, label3.top+10, KScreenWidth-150, 30);
  _nowField2.backgroundColor = myColor;
_nowField2.secureTextEntry = YES;
  [_nowField2 setFont:[UIFont systemFontOfSize:13]];
  _nowField2.textAlignment = NSTextAlignmentLeft;
  _nowField2.delegate = self;
   [self.view addSubview:_nowField2];


}
-(void)loaddata{
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    NSString * userId = [[NSUserDefaults standardUserDefaults]objectForKey:@"userId"];
    NSArray * array = @[@{@"userId":userId},@{@"pwd":_nowField.text}];
    [HttpTools requestWithURL:KExchmain arrays:array method:@"midPwd" success:^(id JSON) {
    NSLog(@"-------%@",JSON);
        [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
       NSString *string = [NSString stringWithFormat:@"%@",JSON];
        if ([string isEqualToString:@"25"]) {
            [self.view makeToast:@"密码修改成功!"];

}else{

        [self.view makeToast:@"密码修改失败!"];

}
    } failure:^(NSError *error) {
        [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
    }];
    
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
